package dtd.PHS.VND_ExchangeRate.ui;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import dtd.PHS.VND_ExchangeRate.R;
import dtd.PHS.VND_ExchangeRate.data.DataProvider;
import dtd.PHS.VND_ExchangeRate.data.RateItem;
import dtd.PHS.VND_ExchangeRate.utils.Helpers;

public class ShareListRateDialog extends Dialog {

	private RateItem shareRate;
	private Activity hostedActivity;
	private ShareInfoDialogCreator creator;

	public ShareListRateDialog(Activity activity) {
		super(activity);
		this.hostedActivity = activity;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		creator = new ShareInfoDialogCreator(this);
	
		creator.setOnShareSMSClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						String content = Helpers.createSMSContent(shareRate, DataProvider.getInstance().getDate().toString());
						Helpers.broadcastSMSIntent(content);
						cancel();
					}
					
				}
		);

		creator.setOnShareEmailClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				String content = Helpers.createSMSContent(shareRate, DataProvider.getInstance().getDate().toString());
				Helpers.broadcastEmailIntent(hostedActivity,content);
				cancel();
			}
			
		});
		

	}

	public void prepare(RateItem shareRate) {
		this.shareRate = shareRate;
		String exchangeRate = getContext().getString(R.string.exchange_rate);
		creator.setTitle(exchangeRate+" "+shareRate.getCurrencyName());
	}

}
